const pathToRegexp = require('path-to-regexp');

const { parse, compile } = pathToRegexp;

// pathToRegExp(path: string, key?: key[], options?: TokensToRegExpOptions)
const matchReg = pathToRegexp('/view/vap/want-comp/:searchParams*', [], {
  end: true,
  sensitive: false,
  strict: false,
});


console.log('matchReg %o', matchReg);
console.log('nowithBegin: %o', matchReg.exec('/user'));
console.log('singleParams: %o', matchReg.exec('/view/vap/want-comp/1'));
console.log('multiParams: %o', matchReg.exec('/view/vap/want-comp/1/12/2021-01-08/2021-01-09/2'));
console.log('optionalsParams: %o', matchReg.exec(`/view/vap/want-comp/${encodeURIComponent('1/12///2')}`));

// match(path: string, options?: TokensToRegExpOptions & ParseOptions)
// const matcher = match('/user/(:usercId+)?');
// /^\/view\/vap\/want-comp\/((?:[^\/]+?)(?:\/(?:[^\/]+?))*)(?:\/(?=$))?$/i
// /^\/view\/vap\/want-comp\/(?:([^\/]+?))+\/?$/i
// /^\/view\/vap\/want-comp(?:\/((?:[^\/#\?]+?)(?:\/(?:[^\/#\?]+?))*))[\/#\?]?$/i
// /^\/view\/vap\/want-comp\/(?:([^\/]+?))+\/?$/i

// console.log('matcher ->\r\n%o', matcher('/user/121212'));


// parse(path:string, options?:ParseOptions): Token[]
const tokens = parse('/user/:segment+');
console.table(tokens);

// compile(str: string, options?: TokenToFunctionOptions & ParseOptions): PathFunction
const toPath = compile('/user/:segment+');

console.log('path => \r\n %s', toPath({ segment: ['949484','2021-01-09', '2'] }));